<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模块的继承</title>
</head>
<body>
    <h1>模块的继承</h1>

    <script type="module">
        // 基础模块
        // circleModule.js
        const PI = Math.PI;

        export function area(radius) {
            return PI * radius * radius;
        }

        export function circumference(radius) {
            return 2 * PI * radius;
        }

        // 继承模块
        // circleExtendedModule.js
        export * from './circleModule.js';
        export function diameter(radius) {
            return radius * 2;
        }

        // 实际应用示例
        // base-validator.js
        export class BaseValidator {
            validate(value) {
                if (value === undefined || value === null) {
                    return false;
                }
                return true;
            }
        }

        // string-validator.js
        import { BaseValidator } from './base-validator.js';
        export class StringValidator extends BaseValidator {
            validate(value) {
                if (!super.validate(value)) return false;
                return typeof value === 'string';
            }
        }

        // number-validator.js
        import { BaseValidator } from './base-validator.js';
        export class NumberValidator extends BaseValidator {
            validate(value) {
                if (!super.validate(value)) return false;
                return typeof value === 'number' && !isNaN(value);
            }
        }

        // validators/index.js
        export * from './base-validator.js';
        export * from './string-validator.js';
        export * from './number-validator.js';

        // 使用示例
        import { StringValidator, NumberValidator } from './validators/index.js';

        const stringValidator = new StringValidator();
        const numberValidator = new NumberValidator();

        console.log(stringValidator.validate('hello')); // true
        console.log(stringValidator.validate(123)); // false
        console.log(numberValidator.validate(123)); // true
        console.log(numberValidator.validate('123')); // false
    </script>
</body>
</html> 